// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()
const todos = db.collection('todos')

// 云函数入口函数
exports.main = async (event, context) => {
  let myDate = new Date;
  let month = myDate.getMonth() + 1;
  let day = myDate.getDay();
  let year = myDate.getFullYear();
  let minute = myDate.getMinutes();
  let time = `${year}-${month}-${day} ${minute}:00`
  let tasks = await todos.where({
    status: 'in-progress',
    time: time,
  }).get();
  console.log(tasks)

  for(i=0;i<task.data.length;i++){
    await cloud.callFunction({
      name: 'msgMe',
      data:{
        formId: tasks.data[i].formId,
        taskId: tasks.data[i]._id
      }
    })
  }

  const wxContext = cloud.getWXContext()

  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}